{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Installation and deployment of 5G System using the Open Air Interface (OAI)\n",
    "## Objectives\n",
    "- Install and Deploy 5GC, gNB and UE using OAI wiht Docker\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5GC Installation\n",
    "\n",
    "In a Linux Terminal, follow the steps below:\n",
    "\n",
    "**Step 0:** Setup your VM or Baremetal Machine, after install Useful Software:\n",
    "\n",
    "sudo su\n",
    "\n",
    "apt update -y\n",
    "\n",
    "apt upgrade -y\n",
    "\n",
    "apt install -y python3-pip git curl cmake tree golang vim net-tools build-essential nfs-common openssh-server\n",
    "\n",
    "**Step 1:** Install dependencies\n",
    "\n",
    "sudo apt-get install ca-certificates \n",
    "\n",
    "sudo apt-get install curl \n",
    "\n",
    "sudo apt-get install gnupg \n",
    "\n",
    "sudo apt-get install lsb-release \n",
    "\n",
    "**Step 2:** Enable packet forwarding\n",
    "\n",
    "sudo sysctl net.ipv4.conf.all.forwarding=1\n",
    "\n",
    "sudo iptables -P FORWARD ACCEPT\n",
    "\n",
    "**Step 3:** Install docker and docker-compose\n",
    "\n",
    "sudo rm /etc/apt/sources.list.d/docker.list*\n",
    "\n",
    "sudo mkdir -p /etc/apt/keyrings \n",
    "\n",
    "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -\n",
    "\n",
    "sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu \\\\$(. /etc/os-release; echo \"\\\\$UBUNTU_CODENAME\") stable\"\n",
    "\n",
    "sudo chmod a+r /etc/apt/keyrings/docker.gpg\n",
    "\n",
    "sudo apt-get update\n",
    "\n",
    "sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin\n",
    "\n",
    "```python \n",
    "sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose\n",
    "```\n",
    "\n",
    "sudo chmod +x /usr/local/bin/docker-compose\n",
    "\n",
    "**Step 4:** Pull the images from Docker Hub\n",
    "\n",
    "docker pull mysql:8.0\n",
    "\n",
    "docker pull oaisoftwarealliance/oai-amf:v1.5.0\n",
    "\n",
    "docker pull oaisoftwarealliance/oai-nrf:v1.5.0\n",
    "\n",
    "docker pull oaisoftwarealliance/oai-smf:v1.5.0\n",
    "\n",
    "docker pull oaisoftwarealliance/oai-spgwu-tiny:v1.5.0\n",
    "\n",
    "docker pull oaisoftwarealliance/trf-gen-cn5g:focal\n",
    "\n",
    "docker pull oaisoftwarealliance/oai-gnb:develop\n",
    "\n",
    "docker pull oaisoftwarealliance/oai-nr-ue:develop\n",
    "\n",
    "\n",
    "**Step 5:** Clone OpenAirInterface 5G Core repository\n",
    "\n",
    "git clone https://gitlab.eurecom.fr/oai/openairinterface5g.git\n",
    "\n",
    "cd ci-scripts/yaml_files/5g_rfsimulator\n",
    "\n",
    "\n",
    "**Step 6:** Install and deploy 5GC:\n",
    "\n",
    "docker-compose up -d mysql oai-nrf oai-amf oai-smf oai-spgwu oai-ext-dn\n",
    "\n",
    "**Step 7:** Wait for a bit and test using:\n",
    "\n",
    "docker-compose ps -a\n",
    "\n",
    "You will see\n",
    "     \n",
    "![5GC_deploy_02](../FIGS/H01_FAST_UNI_III/img_01.png)\n",
    "\n",
    "**Step 8:** Take care, to execute this step, the whole 5GC SHALL be in healthy state (especially the mysql container). Deploy monolithic gNB:\n",
    "\n",
    "docker-compose up -d oai-gnb\n",
    "\n",
    "**Step 9:** Wait for a bit and test using:\n",
    "\n",
    "docker-compose ps -a\n",
    "\n",
    "You will see\n",
    "     \n",
    "![5GC_deploy_02](../FIGS/H01_FAST_UNI_III/img_02.png)\n",
    "\n",
    "\n",
    "**Step 10:** You can verify that the gNB is connected with the AMF:\n",
    "\n",
    "docker logs rfsim5g-oai-amf\n",
    "\n",
    "![5GC_deploy_02](../FIGS/H01_FAST_UNI_III/img_03.png)\n",
    "\n",
    "**Step 11:** Deploy OAI NR-UE in RF simulator mode and in Standalone Mode\n",
    "\n",
    "docker-compose up -d oai-nr-ue\n",
    "\n",
    "\n",
    "**Step 10:** Wait for a bit and test using:\n",
    "\n",
    "docker-compose ps -a\n",
    "\n",
    "![5GC_deploy_02](../FIGS/H01_FAST_UNI_III/img_04.png)\n",
    "\n",
    "\n",
    "**Step 13:** You can verify that the gNB is connected with the AMF:\n",
    "\n",
    "docker logs rfsim5g-oai-amf\n",
    "\n",
    "\n",
    "**Step 14:** Making sure the OAI UE is connected\n",
    "\n",
    "docker exec -it rfsim5g-oai-nr-ue /bin/bash\n",
    "\n",
    "Inside docker type: ifconfig\n",
    "\n",
    "You will see:\n",
    "\n",
    "![5GC_deploy_02](../FIGS/H01_FAST_UNI_III/img_05.png)\n",
    "\n",
    "Type **exit** to return outside the UE pod.\n",
    "\n",
    "**Step 15:** Deploy Second OAI NR-UE in RF simulator mode and in Standalone Mode\n",
    "\n",
    "docker-compose up -d oai-nr-ue2\n",
    "\n",
    "**Step 16:** start a iperf server inside U1\n",
    "\n",
    "docker exec -it rfsim5g-oai-nr-ue1 /bin/bash\n",
    "\n",
    "Inside docker type: iperf -B 12.1.1.2 -u -i 1 -s\n",
    "\n",
    "You will see:\n",
    "\n",
    "![5GC_deploy_02](../FIGS/H01_FAST_UNI_III/img_06.png)\n",
    "\n",
    "**Step 16:** open a new terminal and start a iperf client inside UE2\n",
    "\n",
    "docker exec -it rfsim5g-oai-nr-ue /bin/bash\n",
    "\n",
    "Inside docker type: iperf -c 12.1.1.2 -u -i 1 -t 20 -b 500K\n",
    "\n",
    "You will see:\n",
    "\n",
    "![5GC_deploy_02](../FIGS/H01_FAST_UNI_III/img_07.png)\n",
    "\n",
    "\n",
    "**Step 17:** to undeploy everything\n",
    "\n",
    "docker-compose down\n",
    "\n",
    "\n",
    "\n",
    "**Source:** https://gitlab.eurecom.fr/oai/openairinterface5g/-/tree/develop/ci-scripts/yaml_files/5g_rfsimulator"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
